package com.dps.omc.strategy.handler;

import com.dps.omc.model.AgentNode;
import com.dps.omc.model.DbServer;
import com.dps.omc.model.TemplateHandler;
import com.dps.omc.service.IDbServerService;
import com.dps.omc.task.message.PassConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Created by lip on 2016-01-11.
 */
@Component
public class DbServerStep implements IStepHandler{
    @Autowired
    private IDbServerService dbServerService;
    @Override
    public void process(AgentNode agentNode, Map<String, String> data, TemplateHandler templateHandler) {

        DbServer dbServer = dbServerService.fetch(agentNode.getNodeId());
        if(dbServer!=null)
        {
            data.put("dbHost",dbServer.getDbHost());
            data.put("dbName",dbServer.getDbName());
            data.put("dbUser",dbServer.getDbUser());
            String pass = PassConstants.PASS_START+dbServer.getDbPass()+PassConstants.PASS_END;
            data.put("dbPass",pass);
            data.put("dbPort",dbServer.getDbPort());
        }
    }
}
